package Multithreading.Exercise005;

/**
 * ClassName:RunnableDome
 * Package:Multithreading.Exercise005
 * Description:
 *
 * @Author:ZhangXin
 * @Create:2023/3/6-22:03
 * @Version:v1.0
 */
public class MyRunnable implements Runnable {
    int count = 100;

    @Override
    public void run() {
        while (true){
            if (getCount()) break;
        }
    }
    private synchronized boolean getCount() {
        if (count<10){
            return true;
        }else {
            try {
                Thread.sleep(20);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            count--;
            System.out.println(Thread.currentThread().getName()+"送完还剩"+count+"件礼品");
        }
        return false;
    }
}
